home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / os2 / os2cl015.zip / provadlg.cpp < prev    next >
C/C++ Source or Header  |  1995-11-24  |  6KB  |  238 lines

  1. /* 
  2.  
  3.  
  4.     provadlg.cpp (emx+gcc) 
  5.  
  6.     1995 Giovanni Iachello
  7.     This is freeware software. You can use or modify it as you wish,
  8.     provided that the part of code that I wrote remains freeware.
  9.     Freeware means that the source code must be available on request 
  10.     to anyone.
  11.     You must also include this notice in all files derived from this
  12.     file.
  13.  
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #define INCL_WIN
  20. #include "pmwin.h"
  21. #include "pmdlg.h"
  22. #include "pmgpi.h"
  23. #include "pmhelp.h"
  24. #include "pmstdres.h"
  25. #include "provadlg.h"
  26.  
  27. PMApp* App;
  28.  
  29. PMHelpWin *helpwin;
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32.  
  33. BOOL helpHook ( HAB habAnchor, SHORT sMode, USHORT usTopic, USHORT usSubTopic, PRECTL prclPos )
  34. {
  35.     if ( (sMode == HLPM_WINDOW ) && helpwin ) {
  36.         helpwin->sendMsg(HM_DISPLAY_HELP, 
  37.             MPFROMLONG (MAKELONG (usTopic, 0)), MPFROMSHORT( HM_RESOURCEID) );
  38.         return TRUE;
  39.     } 
  40.     return FALSE;
  41. }
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44.  
  45. class NamesDialog : public PMModalDialog {
  46. public:
  47.     NamesDialog(HWND parent,HWND owner,ULONG id,PMControlMap* cm,void* obj) :
  48.         PMModalDialog(parent,owner,id,cm,obj) {};
  49.     BOOL initdlg() {
  50.         char buf[64];
  51.         PMListBox* lb=(PMListBox*)controlFromID(DNAME_LB_NAMELIST);
  52.         lb->insertItem(LIT_END,"Mario");
  53.         lb->insertItem(LIT_END,"Luca");
  54.         lb->insertItem(LIT_END,"Piero");
  55.         lb->insertItem(LIT_END,"Marco");
  56.         lb->insertItem(LIT_END,"Giovanni");
  57.         ab.loadString( STR_PAOLA, 64, buf);
  58.         lb->insertItem( LIT_END, buf);
  59.         ab.loadString( STR_CHIARA, 64, buf);
  60.         lb->insertItem( LIT_END, buf);
  61.         ab.loadString( STR_SILVIA, 64, buf);
  62.         lb->insertItem( LIT_END, buf);
  63.         return TRUE;
  64.     }        
  65.     BOOL control(SHORT id,SHORT ctrlmsg) {
  66.         switch (id) {
  67.         case DNAME_LB_NAMELIST:
  68.             switch (ctrlmsg) {
  69.                 case LN_SELECT: 
  70.                     char buf[64];
  71.                     SHORT sIndex;
  72.  
  73.                     PMListBox* ctl=(PMListBox*)controlFromID(DNAME_LB_NAMELIST);
  74.  
  75.                     sIndex=ctl->querySelection();
  76.                     ctl->queryItemText(sIndex,buf,64);
  77.                     
  78.                     controlFromID(DNAME_EF_NAME)->setText(buf);
  79.                       return TRUE;
  80.                 case LN_ENTER:                                              // @10
  81.                     postMsg(WM_COMMAND,MPFROMSHORT(DID_OK),0);
  82.                     return TRUE;
  83.             } /* endswitch */
  84.         } /* endswitch */
  85.         return FALSE;
  86.     }         
  87. };
  88.  
  89. class PMPrintThread : public PMWindowThread {
  90. public:
  91.     PMPrintThread() : PMWindowThread() {
  92.     }
  93.     void main(void* arg=NULL) {
  94.         PMPrinterDC printer(hab);
  95.         printer.open();
  96.         printer.startDoc("docdiprova");
  97.  
  98.         PMPresSpace *ptr=new PMPresSpace(&printer,0,0,PU_LOMETRIC|PU_LOENGLISH|GPIF_DEFAULT|GPIT_NORMAL|GPIA_ASSOC,hab);
  99.         PMPoint points[4]={ PMPoint(0,0), PMPoint(900,0), PMPoint(0,900), PMPoint(900,900) };
  100.         ptr->move(&points[0]);
  101.         ptr->line(&points[1]);
  102.         ptr->line(&points[2]);
  103.         ptr->line(&points[3]);
  104.         ptr->line(&points[0]);
  105.  
  106.         delete ptr;
  107.         printer.endDoc("docdiprova");
  108.     }
  109. };
  110.  
  111. class Pippo : public PMMainWin {
  112.     struct pluto {
  113.         int lbsel;
  114.         char nome[64];
  115.     } temp;
  116. public:
  117.     Pippo(HAB ab,PMHelpWin* hw) : PMMainWin("pippo.child",ab,hw) {
  118.         createArgs->flCreateFlags|=FCF_MENU|FCF_ICON|FCF_ACCELTABLE;
  119.         createArgs->idResources=ID_PROVADLG;
  120.         createArgs->pszTitle="Pippo";
  121.         strcpy(temp.nome,"Collo");
  122.         temp.lbsel=1;
  123.     } ;
  124.     BOOL paint(PMPresSpace& ps)
  125.     {
  126.         char buf[100];
  127.         sprintf( buf, "ProvaDlg main window '%s'", temp.nome);
  128.         PMRect rcl;
  129.         rcl=this;
  130.           ps.setColor (CLR_DARKCYAN);
  131.           ps.drawText (-1, buf, &rcl, 0, 0, DT_TEXTATTRS | DT_CENTER | DT_VCENTER | DT_ERASERECT);
  132.         return TRUE;
  133.     }
  134.     BOOL command(USHORT id,USHORT cmddev)
  135.     {
  136.         switch (id) {
  137.             case IDM_CRASH: {
  138. /*                PMControlMap plutocm[] ={
  139.                     cmListBox(DNAME_LB_NAMELIST , pluto,lbsel)
  140.                     cmEntryField(DNAME_EF_NAME,pluto,nome)
  141.                     cmEnd(DNAME_EF_NAME)
  142.                 };
  143.                 NamesDialog mio(HWND_DESKTOP,hwnd,DLG_NAME,plutocm,&temp);*/
  144.  
  145.                 PMControlMap esempio1cm[] ={
  146.                     cmEntryField(D1_NOME,pluto,nome)
  147.                     cmEnd(D1_NOME)
  148.                 };
  149.                 PMModalDialog mio(HWND_DESKTOP,hwnd,DLG_ESEMPIO1,esempio1cm,&temp);
  150.                 int ret=mio.createWin(); // run dialog
  151.                 if (ret) invalidate(TRUE);
  152.                 return TRUE;
  153.             }
  154.             case IDM_FONTS:    {
  155.                 FONTMETRICS fm;
  156.                 PMWindowPresSpace ps(this);
  157.                 ps.queryFontMetrics(&fm);
  158.                 PMFontDialog fd(HWND_DESKTOP,hwnd, &fm,0,"Titolo","Preview");
  159.                 int ret=fd.createWin();
  160.                 assert(ret);
  161.                 FONTDLG fi=fd;
  162.                 msgBox("Result","%d %s %ld %hd %hd %hd %hd",ret,fi.pszFamilyname,fi.fxPointSize,fi.usWeight,fi.usWidth,fi.x,fi.y);
  163.                 return TRUE;
  164.             }
  165.         }        
  166.         return PMMainWin::command(id,cmddev);
  167.     }
  168. /*    BOOL kbd(PMEvent& event) {
  169.         char buf[160];
  170.         sprintf(buf,"fs: %u  repeat: %u   scan: %u  chr: %u  vkey: %u",
  171.             event.charmsg->fs,event.charmsg->cRepeat,event.charmsg->scancode,
  172.             event.charmsg->chr,event.charmsg->vkey);
  173.         WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,buf,"KEYBOARDHIT",0,MB_OK);
  174.         return TRUE;
  175.     }*/
  176.     BOOL fileOpen(PCSZ filename) {
  177.         char buf[200];
  178.         msgBox("Result","%s ",filename);
  179.         
  180.         return TRUE;
  181.     }
  182.     BOOL filePrint() {
  183.         new PMPrintThread;
  184.         return TRUE;
  185.     }
  186.     BOOL helpmsg(PMEvent &event)
  187.     {
  188.         if (event.msg==HM_QUERY_KEYS_HELP) {
  189.             event.ret=MRFROMSHORT(HLP_PROVADLG_KEYS); 
  190.             return TRUE;
  191.         }
  192.         return FALSE;
  193.     }
  194.     BOOL help(PMEvent &event)
  195.     {
  196.         return FALSE;
  197.     }
  198.     
  199. };
  200.  
  201.  
  202. int main (int argc,char* argv[])
  203. {
  204.     PMAnchorBlock ab;
  205.     PMMessageQueue mq;
  206.     ab.init();
  207.     mq.create(ab);
  208.     
  209.     App=new PMApp(ab,mq,argc,argv);
  210.  
  211.     helpwin=new PMHelpWin("Prova Dlg Sample Help File","provadlg.hlp",ID_PROVADLG,ab);
  212.     helpwin->createWin();
  213.  
  214.     Pippo * pip=new Pippo(ab,helpwin);
  215.     pip->createWin();
  216.  
  217.     ab.setHook(mq,HK_HELP,(PFN)helpHook,NULLHANDLE);
  218.     
  219.     App->run();
  220.  
  221.     ab.releaseHook(mq,HK_HELP,(PFN)helpHook,NULLHANDLE);
  222.  
  223.     pip->destroyWin();
  224.  
  225.     delete helpwin;
  226.  
  227.     mq.destroy();
  228.     ab.uninit();
  229.  
  230.     return (0);
  231. }
  232.  
  233. /*
  234.  * Local variables:
  235.  * compile-command: "dmake provadlg.exe"
  236.  * end:
  237.  */
  238.